//
//  addMoreController.m
//  Focus
//
//  Created by dlios on 14-10-28.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "addMoreController.h"
#import "recommendController.h"

@interface addMoreController ()<WWTagsCloudViewDelegate>

@end

@implementation addMoreController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:226/255.0 green:44/255.0 blue:56/255.0 alpha:1.0];
#pragma mark -
#pragma mark - 导航栏标题设置
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    title.backgroundColor = [UIColor clearColor];
    title.text = @"调节阅读偏好";
    title.textColor = [UIColor whiteColor];
    title.font = [UIFont systemFontOfSize:18];
    title.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = title;
    [title release];
#pragma mark -
#pragma mark - 导航栏左边自定义button
    UIButton *left = [UIButton buttonWithType:UIButtonTypeCustom];
    left.frame = CGRectMake(0, 0, 40, 40);
    [left setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [left addTarget:self action:@selector(leftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithCustomView:left]autorelease];
#pragma mark -
#pragma mark - segmentControl
    NSArray *nameArr = [NSArray arrayWithObjects:@"我的偏好",@"添加更多偏好", nil];
    UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:nameArr];
    self.seg = seg;
    [seg release];
    _seg.frame = CGRectMake(0, 0, 320, 40);
    _seg.selectedSegmentIndex = 0;
    _seg.tintColor = [UIColor whiteColor];
    _seg.backgroundColor = [UIColor colorWithRed:226/255.0 green:44/255.0 blue:56/255.0 alpha:1.0];
    [_seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_seg];
    [_seg release];
#pragma mark -
#pragma mark - 创建scrollView
    [self creatScroll];
}
#pragma mark -
#pragma mark - 导航栏右边自定义button点击事件
-(void)leftButtonAction:(UIBarButtonItem *)sender{
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}
#pragma mark -
#pragma mark - seg点击事件
-(void)segAction:(UISegmentedControl *)seg{
    //seg点击事件的根据self.scroll.contentOffset判断
    if (seg.selectedSegmentIndex == 0) {
        self.scroll.contentOffset = CGPointMake(0, 0);
        
    }else if (seg.selectedSegmentIndex == 1){
        self.scroll.contentOffset =  CGPointMake(320, 0);
    }
}
#pragma mark -
#pragma mark - scrollView
-(void)creatScroll{
    UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, 320, 568-89)];
    self.scroll = scroll;
    [scroll release];
    _scroll.backgroundColor = [UIColor whiteColor];
    _scroll.delegate = self;
    _scroll.bounces = NO;
    _scroll.contentSize = CGSizeMake(640, 0);
    _scroll.scrollEnabled = YES;
    [self.view addSubview:_scroll];
    //创建我的偏好view
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568-89)];
    view1.backgroundColor = [UIColor whiteColor];
    [_scroll addSubview:view1];
    [view1 release];
    //创建添加更多偏好view
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(320, 0, 320, 569 - 89)];
    view2.backgroundColor = [UIColor whiteColor];
    [_scroll addSubview:view2];
    [view2 release];
    //创建我的偏好里面的label
    UILabel *content = [[UILabel alloc]initWithFrame:CGRectMake(30, 120, 260, 60)];
    content.text = @"告诉我们你的阅读偏好,我们将会推荐给你更多感兴趣的内容";
    content.textColor = [UIColor grayColor];
    content.numberOfLines = 5;
    content.textAlignment = NSTextAlignmentCenter;
    content.font = [UIFont systemFontOfSize:14];
    [view1 addSubview:content];
    [content release];
    //创建我的偏好里面的button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(130, 180, 60, 30);
    button.backgroundColor = [UIColor whiteColor];
    [button setTitle:@"立即添加" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    //边框
    button.layer.borderWidth = 1;
    button.layer.borderColor = [UIColor blackColor].CGColor;
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(addAction:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:button];
    //创建我们才你还喜欢Label
    UILabel *hobby = [[UILabel alloc]initWithFrame:CGRectMake(18, 90, 150, 20)];
    hobby.text = @"我们猜你还喜欢:";
    hobby.font = [UIFont systemFontOfSize:14];
    [view2 addSubview:hobby];
    [hobby release];
    //创建换一批按钮
    UIButton *change = [UIButton buttonWithType:UIButtonTypeCustom];
    change.frame = CGRectMake(240, 90, 50, 20);
    [change setTitle:@"换一批" forState:UIControlStateNormal];
    change.layer.borderWidth = 0.5;
    change.layer.borderColor = [UIColor blackColor].CGColor;
    [change setTitleColor:[UIColor  colorWithRed:135/255.0 green:206/255.0 blue:250/255.0 alpha:1.0] forState:UIControlStateNormal];
    change.titleLabel.font = [UIFont systemFontOfSize:14];
    [change addTarget:self action:@selector(refreshBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view2 addSubview:change];
    //创建确定按钮
    //    UIButton *yesButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //    yesButton.frame = CGRectMake(100, 300, 100, 30);
    //    yesButton.backgroundColor = [UIColor colorWithRed:226/255.0 green:44/255.0 blue:56/255.0 alpha:1.0];
    //    [yesButton setTitle:@"确定" forState:UIControlStateNormal];
    //    [yesButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //    [view2 addSubview:yesButton];
    //创建添加更多偏好里面的标签云效果
    self.tags = @[@"国际资讯", @"今日看点", @"人物杂志", @"华尔街", @"电影资讯", @"豆瓣点评", @"时光天堂电影小姐", @"天涯小筑美剧资讯", @"杨澜的博客", @"冷笑话精选", @"投资界", @"第一财经日报", @"福布斯中文网", @"胡润中文网", @"APP精选", @"互联网资讯", @"1991T-互联网数据中心", @"互联网的一些事", @"国际足球", @"装备公园", @"汽车之家", @"汽车杂志", @"太平洋汽车网", @"网通社汽车频道", @"教育频道", @"Ficker精选", @"花瓣美女", @"世界国家地理", @"美食天下", @"旅游达人精选"];
    NSArray* colors = @[[UIColor colorWithRed:0 green:0.63 blue:0.8 alpha:1], [UIColor colorWithRed:1 green:0.2 blue:0.31 alpha:1], [UIColor colorWithRed:0.53 green:0.78 blue:0 alpha:1], [UIColor colorWithRed:1 green:0.55 blue:0 alpha:1]];
    NSArray* fonts = @[[UIFont systemFontOfSize:12], [UIFont systemFontOfSize:16], [UIFont systemFontOfSize:18]];
    _tagCloud = [[WWTagsCloudView alloc] initWithFrame:CGRectMake(0, 100, 320, 200)
                                               andTags:_tags
                                          andTagColors:colors
                                              andFonts:fonts
                                       andParallaxRate:1.7
                                          andNumOfLine:3];
    _tagCloud.delegate = self;
    [view2 addSubview:_tagCloud];
    //创建添加爱好按钮
    UIButton *hobbyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    hobbyButton.frame = CGRectMake(18, 30, 200, 30);
    [hobbyButton setTitle:@"添加猜你喜欢的内容:" forState:UIControlStateNormal];
    hobbyButton.titleLabel.textAlignment = NSTextAlignmentLeft;
    hobbyButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [hobbyButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    hobbyButton.layer.borderWidth = 1;
    hobbyButton.layer.borderColor = [UIColor grayColor].CGColor;
    [view2 addSubview:hobbyButton];
    //创建加号button
    UIButton *jiahao = [UIButton buttonWithType:UIButtonTypeCustom];
    jiahao.frame = CGRectMake(218, 30, 70, 30);
    jiahao.layer.borderWidth = 1;
    jiahao.layer.borderColor = [UIColor grayColor].CGColor;
    [jiahao setBackgroundImage:[UIImage imageNamed:@"addRootBlock_cell_add.png"] forState:UIControlStateNormal];
    [view2 addSubview:jiahao];
    
    
}
#pragma mark -
#pragma mark - scrollViewDelegate的协议监听偏移量

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //打印结构体
    NSLog(@"%@",NSStringFromCGPoint(scrollView.contentOffset));
    //如果偏移量为320上面seg变化为1反之为0
    if (scrollView.contentOffset.x == 320) {
        self.seg.selectedSegmentIndex = 1;
    }else{
        self.seg.selectedSegmentIndex = 0;
    }
    NSLog(@"偏移量改变");
    
}
#pragma mark -
#pragma mark - 标签云效果的点击事件方法
-(void)tagClickAtIndex:(NSInteger)tagIndex
{
    NSLog(@"%@",_tags[tagIndex]);
    
}

- (void)refreshBtnClick:(UIButton*)sender {
    [_tagCloud reloadAllTags];
}
#pragma mark -
#pragma mark - 添加Action
-(void)addAction:(UIButton *)sender{
    self.seg.selectedSegmentIndex = 1;
}
#pragma mark -
#pragma mark - changeAction
-(void)changeAction:(UIButton *)sender{
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
